package com.movecar.ui;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import BLLocationCallbacker.PopWindowsCallbacker;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.movecar.R;
import com.movecar.adapter.HomeAdImagePagerAdapter;
import com.movecar.adapter.ImageAdapter;
import com.movecar.dialog.CustomDialog;
import com.movecar.listview.WaterFallListView;
import com.movecar.listview.WaterFallListView.IXListViewListener;
import com.movecar.model.AdPicBean;
import com.movecar.model.CloudBeansBean;
import com.movecar.model.GroupBean;
import com.movecar.model.HomeInfoBean;
import com.movecar.model.NewMessageNumBean;
import com.movecar.model.Pictures;
import com.movecar.utils.Alert;
import com.movecar.utils.AppConfig;
import com.movecar.utils.Converter;
import com.movecar.utils.DataStore;
import com.movecar.utils.HttpPostRequestAsyncTask;
import com.movecar.utils.ListUtils;
import com.movecar.utils.PopupWindowAnimation;
import com.movecar.utils.RequestResultCallback;
import com.movecar.utils.imageloader.Constants;
import com.movecar.widget.CustomProgressDialog;
import com.movecar.widget.HomeGroundImageview;
import com.movecar.widget.MyGridView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.rockerhieu.emojicon.EmojiconTextView;
import com.zbar.lib.CaptureActivity;

public class NewHomeActivity extends Activity implements OnClickListener, IXListViewListener {

	// private ListView mListView;
	private RelativeLayout titleBar;
	private CustomProgressDialog progressDialog = null;
	protected WaterFallListView mXList;
	private DataAdapter dataAdapter;
	private Button addButton, btn_back, btn_icon, btn_right_message;
	private String userId = "0", userName;
	private String pageNo = "0";
	private boolean flgMore = false;
	private CloudBeansBean mCloudBeansBean;
	private AdPicBean mAdPicBean;
	private NewMessageNumBean mNewMessageNumBean;
	private LayoutInflater layoutInflater;
	private List<HomeInfoBean> mDataList = new ArrayList<HomeInfoBean>();
	private List<HomeInfoBean> resultList = new ArrayList<HomeInfoBean>();
	private List<AdPicBean> AdPicBeanList;
	private HomePopWindow typePop;
	private ImageView arrow;
	private RelativeLayout navi_new_tip;
	private SharedPreferences sharedPreferences;
	private String sectionId = "0";
	private String groupMessageId = "0";
	private String pmId = "0";
	private String myFlag = "0";
	private long mExitTime = 0;
	/** 获取库Phon表字段 **/
	private static final String[] PHONES_PROJECTION = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER, Photo.PHOTO_ID,
			Phone.CONTACT_ID };
	/** 联系人显示名称 **/
	private static final int PHONES_DISPLAY_NAME_INDEX = 0;

	/** 电话号码 **/
	private static final int PHONES_NUMBER_INDEX = 1;

	/** 联系人名称 **/
	private ArrayList<String> mContactsName = new ArrayList<String>();

	/** 联系人电话 **/
	private ArrayList<String> mContactsNumber = new ArrayList<String>();

	/** 联系人头像 **/
	// private ArrayList<Bitmap> mContactsPhonto = new ArrayList<Bitmap>();
	private ImageLoader imageLoader = null;
	private RelativeLayout new_message_1, new_message_2;
	private android.view.animation.Animation animation, animation_NewMessage_in, animation_NewMessage_out;
	private int home_new_tip_2;
	private int home_new_tip_3;
	private TextView title;
	private ImageView user_img1, user_img2;
	private AutoScrollViewPager adImg;
	private LinearLayout adIndex;
	private TextView message_content1, message_content2, num1, num2;
	private String sectionName, group_name;
	private View headview;
	private View mainView;

	private ImageView[] indicator_imgs;// 存放引到图片数组

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mainView = layoutInflater.inflate(R.layout.new_home_ground, null);
		setContentView(mainView);
		home_new_tip_2 = getIntent().getIntExtra("home_new_tip_2", 0);
		home_new_tip_3 = getIntent().getIntExtra("home_new_tip_3", 0);
		initView();
	}

	private void initView() {

		startProgressDialog();
		// 检查是否获取通讯录信息
		isCheckContact();

		imageLoader = ImageLoader.getInstance();
		// //imageLoader.init(Constants.imageLoaderConfiguration(this));
		// 俱乐部
		mXList = (WaterFallListView) findViewById(R.id.mHomeListView);
		mXList.setPullRefreshEnable(true);
		mXList.setPullLoadEnable(true);
		mXList.setXListViewListener(this);

		layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		headview = layoutInflater.inflate(R.layout.main_advertisement, null);

		adImg = (AutoScrollViewPager) headview.findViewById(R.id.ad);
		adIndex = (LinearLayout) headview.findViewById(R.id.indicator);

		addButton = (Button) findViewById(R.id.btn_right);
		arrow = (ImageView) findViewById(R.id.arrow);
		arrow.setImageResource(R.drawable.arrow_down);
		arrow.setVisibility(View.VISIBLE);
		btn_back = (Button) findViewById(R.id.btn_left);
		btn_back.setOnClickListener(this);
		btn_back.setVisibility(View.VISIBLE);

		btn_icon = (Button) findViewById(R.id.btn_icon);
		btn_icon.setOnClickListener(this);
		btn_right_message = (Button) findViewById(R.id.btn_right_message);
		btn_right_message.setOnClickListener(this);
		title = (TextView) findViewById(R.id.title);
		new_message_1 = (RelativeLayout) findViewById(R.id.new_message_1);
		new_message_2 = (RelativeLayout) findViewById(R.id.new_message_2);
		num1 = (TextView) findViewById(R.id.num1);
		num2 = (TextView) findViewById(R.id.num2);
		new_message_1.setOnClickListener(this);
		new_message_2.setOnClickListener(this);
		user_img1 = (ImageView) findViewById(R.id.user_img1);
		user_img2 = (ImageView) findViewById(R.id.user_img2);
		message_content1 = (TextView) findViewById(R.id.message_content1);
		message_content2 = (TextView) findViewById(R.id.message_content2);

		Intent intent = this.getIntent();
		pmId = intent.getStringExtra("pmId");
		if (!TextUtils.isEmpty(getIntent().getStringExtra("userId"))) {// 查看具体用户的分享

			userId = getIntent().getStringExtra("userId");
			userName = getIntent().getStringExtra("userName");
			startProgressDialog();
			getShareList();
			addButton.setVisibility(View.GONE);
			btn_back.setVisibility(View.GONE);
			btn_icon.setVisibility(View.VISIBLE);
			arrow.setVisibility(View.GONE);
			btn_back.setOnClickListener(this);
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("sectionId"))) {// 查看具体商家的分享

			btn_back.setVisibility(View.GONE);
			btn_icon.setVisibility(View.VISIBLE);
			addButton.setVisibility(View.GONE);
			arrow.setVisibility(View.GONE);
			sectionId = getIntent().getStringExtra("sectionId");
			sectionName = getIntent().getStringExtra("sectionName");
			startProgressDialog();
			getShareList();
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("messageId"))) {// 查看具体活动的分享

			btn_back.setVisibility(View.GONE);
			btn_icon.setVisibility(View.VISIBLE);
			addButton.setVisibility(View.GONE);
			arrow.setVisibility(View.GONE);
			groupMessageId = getIntent().getStringExtra("messageId");
			group_name = getIntent().getStringExtra("group_name");
			startProgressDialog();
			getShareList();
		} else {
			getAdPic();
			mXList.addHeaderView(headview);
			addButton.setVisibility(View.VISIBLE);
			addButton.setOnClickListener(this);
			startProgressDialog();
			getShareList();

		}

		dataAdapter = new DataAdapter(NewHomeActivity.this);
		mXList.setAdapter(dataAdapter);

		navi_new_tip = (RelativeLayout) findViewById(R.id.navi_new_tip);
		if (home_new_tip_2 != 0 || home_new_tip_3 != 0) {
			navi_new_tip.setVisibility(View.INVISIBLE);
		} else {
			navi_new_tip.setVisibility(View.INVISIBLE);
		}
		animation = AnimationUtils.loadAnimation(this, R.anim.zan_anim);
		animation_NewMessage_out = AnimationUtils.loadAnimation(this, R.anim.out_left_to_right);
		animation_NewMessage_in = AnimationUtils.loadAnimation(this, R.anim.in_right_to_left);
		// 主页点击title弹出popup列表
		typePop = new HomePopWindow(this, R.layout.popwindows, new PopWindowsCallbacker() {

			@Override
			public void onClick(String type) {

				arrow.setImageResource(R.drawable.arrow_down);
				// mXList.startRefresh();

				if ("我的分享".equals(type)) {
					startProgressDialog("正在刷新，请稍后...");
					title.setText(type);
					myFlag = "1";
					mDataList.clear();
					pageNo = "0";
					flgMore = false;
					getShareList();
				} else if ("好友分享".equals(type)) {
					startProgressDialog("正在刷新，请稍后...");
					title.setText(type);
					myFlag = "2";
					mDataList.clear();
					pageNo = "0";
					flgMore = false;
					getShareList();
				} else {
					startProgressDialog("正在刷新，请稍后...");
					title.setText(type);
					myFlag = "0";
					mDataList.clear();
					pageNo = "0";
					flgMore = false;
					getShareList();
				}

			}
		}, home_new_tip_2, home_new_tip_3);
		typePop.setOnDismissListener(new OnDismissListener() {
			@Override
			public void onDismiss() {
				arrow.setImageResource(R.drawable.arrow_down);
			}
		});
		titleBar = (RelativeLayout) findViewById(R.id.titleBar);

		ButtonOnTouchListener listener = new ButtonOnTouchListener();
		titleBar.setOnTouchListener(listener);
	}

	@Override
	protected void onResume() {
		if (!TextUtils.isEmpty(getIntent().getStringExtra("sectionId"))) {
			title.setText(sectionName);
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("userId"))) {
			title.setText(userName);
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("messageId"))) {
			title.setText(group_name);
		}

		else {
			sharedPreferences = getSharedPreferences("login", Context.MODE_PRIVATE);
			title.setText(sharedPreferences.getString("nickName", DataStore.getInstance().getNickName()));
			title.setOnClickListener(this);
			getNewMessageNum();
		}

		super.onResume();
	}

	// 双击titleBar返回顶部
	public class ButtonOnTouchListener implements OnTouchListener {

		@Override
		public boolean onTouch(View v, MotionEvent event) {

			if (event.getAction() == MotionEvent.ACTION_DOWN) {
				if ((System.currentTimeMillis() - mExitTime) > 2000) {

					mExitTime = System.currentTimeMillis();
				} else {
					mXList.smoothScrollToPosition(0);

				}
				return false;

			}
			return false;

		}
	}

	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {

		case R.id.btn_right:
			intent = new Intent().setClass(NewHomeActivity.this, AddShareAlertActivity.class);
			startActivityForResult(intent, 0);

			break;
		case R.id.btn_icon:
			finish();
			break;
		case R.id.btn_left:
			startActivityForResult(new Intent(getApplicationContext(), CaptureActivity.class), 0);

			break;
		case R.id.title:
			if (typePop != null) {
				if (typePop.isShowing()) {
					arrow.setImageResource(R.drawable.arrow_down);
					typePop.dismiss();

				} else {
					typePop.showAsDropDown(v);
					arrow.setImageResource(R.drawable.arrow_up);
				}
			}
			break;
		case R.id.new_message_1:
			new_message_1.startAnimation(animation_NewMessage_out);
			new_message_1.setVisibility(View.INVISIBLE);
			if ("新的消息".equals(message_content1.getText())) {
				intent = new Intent(NewHomeActivity.this, ReplyInfoActivity.class);
				intent.putExtra("strFlag", "1");
				startActivity(intent);
			} else {
				intent = new Intent(NewHomeActivity.this, FriendsInvitationActivity.class);
				intent.putExtra("strFlag", "1");
				startActivity(intent);
			}
			break;
		case R.id.new_message_2:
			new_message_2.startAnimation(animation_NewMessage_out);
			new_message_2.setVisibility(View.INVISIBLE);
			if ("新的消息".equals(message_content2.getText())) {
				intent = new Intent(NewHomeActivity.this, ReplyInfoActivity.class);
				intent.putExtra("strFlag", "1");
				startActivity(intent);
			} else {
				intent = new Intent(NewHomeActivity.this, FriendsInvitationActivity.class);
				intent.putExtra("strFlag", "1");
				startActivity(intent);
			}

			break;

		case R.id.btn_right_message:
			intent = new Intent(NewHomeActivity.this, HomeMessageManagerActivity.class);
			intent.putExtra("strFlag", "0");
			startActivity(intent);
			break;
		default:
			break;
		}

	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (typePop != null && typePop.isShowing()) {
			arrow.setImageResource(R.drawable.arrow_down);
			typePop.dismiss();

			typePop = null;

		}
		return super.onTouchEvent(event);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
		if (requestCode == 0) {
			if (resultCode == RESULT_OK) {
				if (null != data && data.getBooleanExtra("has_animation", false)) {
					new PopupWindowAnimation(mainView, NewHomeActivity.this);
					getShareList();
				} else {
					startProgressDialog();
					getShareList();
				}

			}
		} else if (requestCode == 1) {
			if (resultCode == RESULT_OK) {
				if (data.getStringExtra("zanCount") == null && !data.getBooleanExtra("delete", false)
						&& data.getBooleanExtra("isreplyed", false)) {
					int position = data.getIntExtra("position", 0);
					Object object = dataAdapter.getItem(position);
					if (object instanceof HomeInfoBean) {
						HomeInfoBean homeInfoBean = (HomeInfoBean) object;
						int commentCount = Integer.parseInt(resultList.get(position).getCommentCount());
						String new_commentCount = resultList.get(position).getNewComment();
						commentCount = commentCount + 1;
						homeInfoBean.setCommentCount(commentCount + "");
						if (!"0".equals(resultList.get(position).getNewComment())) {
							new_commentCount = "0";
							homeInfoBean.setNewComment(new_commentCount);
						}
						dataAdapter.notifyDataSetChanged();
					}

				} else if (data.getBooleanExtra("delete", false)) {
					startProgressDialog();
					getShareList();
				} else if (data.getStringExtra("zanCount") == null && !data.getBooleanExtra("isreplyed", false)) {
					int position = data.getIntExtra("position", 0);
					Object object = dataAdapter.getItem(position);
					if (object instanceof HomeInfoBean) {
						HomeInfoBean homeInfoBean = (HomeInfoBean) object;
						String new_commentCount = resultList.get(position).getNewComment();
						if (!"0".equals(resultList.get(position).getNewComment())) {
							new_commentCount = "0";
							homeInfoBean.setNewComment(new_commentCount);
						}
						dataAdapter.notifyDataSetChanged();
					}
				} else if (data.getStringExtra("zanCount") != null && !data.getBooleanExtra("delete", false)
						&& data.getBooleanExtra("isreplyed", false)) {
					int position = data.getIntExtra("position", 0);
					Object object = dataAdapter.getItem(position);
					if (object instanceof HomeInfoBean) {
						HomeInfoBean homeInfoBean = (HomeInfoBean) object;
						if (Integer.parseInt(homeInfoBean.getPraiseCount())
								- Integer.parseInt(data.getStringExtra("zanCount")) > 0) {
							homeInfoBean.setPraise("0");
						} else if (Integer.parseInt(homeInfoBean.getPraiseCount())
								- Integer.parseInt(data.getStringExtra("zanCount")) < 0) {
							homeInfoBean.setPraise("1");
						} else {

						}
						int commentCount = Integer.parseInt(resultList.get(position).getCommentCount());

						commentCount = commentCount + 1;
						homeInfoBean.setCommentCount(commentCount + "");

						homeInfoBean.setPraiseCount(data.getStringExtra("zanCount"));

						dataAdapter.notifyDataSetChanged();
					}

				} else {
					int position = data.getIntExtra("position", 0);
					Object object = dataAdapter.getItem(position);
					if (object instanceof HomeInfoBean) {
						HomeInfoBean homeInfoBean = (HomeInfoBean) object;
						if (Integer.parseInt(homeInfoBean.getPraiseCount())
								- Integer.parseInt(data.getStringExtra("zanCount")) > 0) {
							homeInfoBean.setPraise("0");
						} else if (Integer.parseInt(homeInfoBean.getPraiseCount())
								- Integer.parseInt(data.getStringExtra("zanCount")) < 0) {
							homeInfoBean.setPraise("1");
						} else {

						}
						homeInfoBean.setPraiseCount(data.getStringExtra("zanCount"));

						dataAdapter.notifyDataSetChanged();
					}
				}
			}
		}
	}

	protected void resetXList() {

		mXList.setRefreshTime(new SimpleDateFormat("H:mm", Locale.CHINA).format(new Date()));
		mXList.stopRefresh();
		mXList.stopLoadMore();
	}

	/**
	 * 导入通讯录
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void addDefaultFriend() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "addDefaultFriendNew3")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("phoneList", mContactsNumber.toString()));
		params.add(new BasicNameValuePair("nameList", mContactsName.toString()));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;

				if ("0".equals(result)) {
					// startProgressDialog();
					getShareList();
				} else {
					Intent next = new Intent(NewHomeActivity.this, PhoneLoginActivity.class);
					// 清空SharedPreferences内数据，重新登录
					SharedPreferences sharedPreferences = getSharedPreferences("login", Context.MODE_PRIVATE);
					Editor editor = sharedPreferences.edit();// 获取编辑器
					editor.clear();
					editor.commit();// 提交修改
					// 清空DataStore
					DataStore.getInstance().setUserId("");
					DataStore.getInstance().setMobile("");
					startActivity(next);
					finish();
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	/**
	 * 点赞
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void praiseShare(String shareId, final int position) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "praiseShareNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("shareId", shareId));
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;
				Gson gson = new Gson();
				try {
					mCloudBeansBean = gson.fromJson(result, CloudBeansBean.class);
				} catch (Exception e) {
					return;
				}
				if ("0".equals(mCloudBeansBean.getResultCode())) {
					if (!TextUtils.isEmpty(mCloudBeansBean.getCoinAlert())) {
						new PopupWindowAnimation(mainView, NewHomeActivity.this);
					}
					stopProgressDialog();

				} else {
					stopProgressDialog();
					Alert.error(NewHomeActivity.this, result);
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	/**
	 * 转发
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void transmitShare(String shareId) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "transmitShareNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("shareId", shareId));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;
				Gson gson = new Gson();
				try {
					mCloudBeansBean = gson.fromJson(result, CloudBeansBean.class);
				} catch (Exception e) {
					return;
				}
				if ("0".equals(mCloudBeansBean.getResultCode())) {
					if (!TextUtils.isEmpty(mCloudBeansBean.getCoinAlert())) {
						new PopupWindowAnimation(mainView, NewHomeActivity.this);
					}
					Alert.info(NewHomeActivity.this, "分享成功");
				} else {
					stopProgressDialog();
					Alert.error(NewHomeActivity.this, result);
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	class DataAdapter extends BaseAdapter {

		private Activity activity;
		private LayoutInflater inflater;
		private List<HomeInfoBean> resultOriginalList = null;
		private List<HomeInfoBean> resultThumbList = null;
		private LinkedList<HomeInfoBean> resultList;

		DataAdapter(Activity activity) {

			this.activity = activity;
			inflater = LayoutInflater.from(activity);
			resultList = new LinkedList<HomeInfoBean>();
		}

		public void addItemLast(List<HomeInfoBean> datas) {
			resultList.addAll(datas);
		}

		public void addItemTop(List<HomeInfoBean> datas) {
			resultList.clear();
			for (HomeInfoBean info : datas) {
				resultList.add(info);
			}
		}

		@Override
		public int getCount() {

			return resultList.size();
		}

		@Override
		public Object getItem(int arg0) {

			return resultList.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {

			return arg0;
		}

		@SuppressWarnings("unchecked")
		@Override
		public View getView(final int position, View view, ViewGroup parent) {
			final ViewHolder viewHolder;
			if (view == null) {
				viewHolder = new ViewHolder();
				view = inflater.inflate(R.layout.new_home_ground_item, null);
				viewHolder.user_img = (ImageView) view.findViewById(R.id.user_img);
				viewHolder.main_img = (HomeGroundImageview) view.findViewById(R.id.main_img);
				viewHolder.user_name = (TextView) view.findViewById(R.id.user_name);
				viewHolder.time = (TextView) view.findViewById(R.id.time);
				viewHolder.time_middle = (TextView) view.findViewById(R.id.time_middle);

				viewHolder.watermark = (ImageView) view.findViewById(R.id.watermark);

				viewHolder.describe_info = (EmojiconTextView) view.findViewById(R.id.describe_info);

				viewHolder.describe_info.setEmojiconSize(Converter.dp2pixel(NewHomeActivity.this, 20));
				viewHolder.message_count = (TextView) view.findViewById(R.id.message_text);
				viewHolder.message_text_new = (TextView) view.findViewById(R.id.message_text_new);
				viewHolder.zan = (Button) view.findViewById(R.id.zan);
				viewHolder.zan_click = (Button) view.findViewById(R.id.zan_click);
				viewHolder.zan_count = (TextView) view.findViewById(R.id.zan_text);
				viewHolder.message = (Button) view.findViewById(R.id.message);
				viewHolder.joined = (Button) view.findViewById(R.id.joined);
				viewHolder.share = (ImageButton) view.findViewById(R.id.share);
				viewHolder.shield = (ImageButton) view.findViewById(R.id.shield);
				viewHolder.share_text = (TextView) view.findViewById(R.id.share_text);
				viewHolder.mGridView = (MyGridView) view.findViewById(R.id.mGridView);
				viewHolder.location = (TextView) view.findViewById(R.id.location);

				view.setTag(viewHolder);
			} else {
				// itemView = (View) view.getTag();
				viewHolder = (ViewHolder) view.getTag();
			}

			// 设置头像
			if (resultList.get(position).getIcon().contains("default")) {
				imageLoader.displayImage(AppConfig.HOST + resultList.get(position).getIcon(), viewHolder.user_img,
						Constants.image_display_options, AppConfig.animateListener);
			} else {
				imageLoader.displayImage(AppConfig.HOST + resultList.get(position).getIcon(), viewHolder.user_img,
						Constants.image_display_options_conner, AppConfig.animateListener);
			}

			//
			viewHolder.share_text.setText(resultList.get(position).getTransmitCount());
			if (!TextUtils.isEmpty(resultList.get(position).getAddress())) {
				viewHolder.location.setVisibility(View.VISIBLE);
				viewHolder.location.setText(resultList.get(position).getAddress());
			} else {
				viewHolder.location.setVisibility(View.GONE);
			}

			if ("0".equals(resultList.get(position).getOoFlag())) {
				viewHolder.joined.setVisibility(View.GONE);
			} else if ("1".equals(resultList.get(position).getOoFlag())) {
				viewHolder.joined.setVisibility(View.VISIBLE);
				viewHolder.joined.setBackgroundResource(R.drawable.get_chance);
			} else if ("2".equals(resultList.get(position).getOoFlag())) {
				viewHolder.joined.setVisibility(View.VISIBLE);
				viewHolder.joined.setBackgroundResource(R.drawable.get_good);
			} else if ("3".equals(resultList.get(position).getOoFlag())) {
				viewHolder.joined.setVisibility(View.VISIBLE);
				viewHolder.joined.setBackgroundResource(R.drawable.home_go_club);

			} else if ("4".equals(resultList.get(position).getOoFlag())) {
				viewHolder.joined.setVisibility(View.VISIBLE);
				viewHolder.joined.setBackgroundResource(R.drawable.have_red_packet);

			} else if ("5".equals(resultList.get(position).getOoFlag())) {
				viewHolder.joined.setVisibility(View.VISIBLE);
				viewHolder.joined.setBackgroundResource(R.drawable.no_red_packet);

			} else {

			}

			// 我也要参加

			viewHolder.joined.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if ("1".equals(resultList.get(position).getOoFlag())) {
						Intent intent = new Intent();
						intent.setClass(NewHomeActivity.this, GroupDetailActivity.class);
						intent.putExtra("from_home", true);
						intent.putExtra("messageId", resultList.get(position).getMessageId());
						startActivity(intent);
					} else if ("2".equals(resultList.get(position).getOoFlag())) {
						startProgressDialog();
						joinToo(resultList.get(position).getShareId(), resultList.get(position).getRbMsgId());
						viewHolder.joined.setVisibility(View.GONE);
					} else if ("3".equals(resultList.get(position).getOoFlag())) {
						if ("0".equals(resultList.get(position).getSsType())) {
							Intent intent = new Intent();
							intent.setClass(activity, ClubDetailActivity.class);
							intent.putExtra("sectionId", resultList.get(position).getSectionId());
							startActivity(intent);
						} else if ("2".equals(resultList.get(position).getSsType())) {
							Intent intent = new Intent();
							intent.setClass(activity, RecommendClubDetailActivity.class);
							intent.putExtra("sectionId", resultList.get(position).getSectionId());
							startActivity(intent);
						} else {

						}
					} else {

					}

				}
			});
			viewHolder.shield.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					CustomDialog.Builder customBuilder = new CustomDialog.Builder(NewHomeActivity.this);
					ImageView img = new ImageView(NewHomeActivity.this);
					img.setImageResource(R.drawable.ic_launcher);
					customBuilder.setImgIcon(img).setMessage("请选择操作")

					.setPositiveButton("屏蔽", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							reportShare(resultList.get(position).getShareId(), "0");
							resultList.remove(position);
							dataAdapter.notifyDataSetChanged();
							dialog.dismiss();

						}
					}).setNegativeButton("屏蔽并举报", new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							reportShare(resultList.get(position).getShareId(), "1");
							resultList.remove(position);
							dataAdapter.notifyDataSetChanged();
							dialog.dismiss();

						}
					});
					customBuilder.create().show();

				}
			});
			if (TextUtils.isEmpty(resultList.get(position).getWatermark())) {
				viewHolder.watermark.setVisibility(View.GONE);

			} else {
				viewHolder.watermark.setVisibility(View.VISIBLE);
				imageLoader.displayImage(AppConfig.HOST + resultList.get(position).getWatermark(),
						viewHolder.watermark, Constants.image_display_options, AppConfig.animateListener);

			}
			if (TextUtils.isEmpty(resultList.get(position).getAddress())) {
				viewHolder.time.setText(resultList.get(position).getCreateTime());
				viewHolder.time.setVisibility(View.VISIBLE);
				viewHolder.time_middle.setVisibility(View.GONE);
			} else {
				viewHolder.time_middle.setText(resultList.get(position).getCreateTime());
				viewHolder.time_middle.setVisibility(View.VISIBLE);
				viewHolder.time.setVisibility(View.INVISIBLE);
			}

			viewHolder.user_name.setText(resultList.get(position).getNickname());
			viewHolder.describe_info.setText(resultList.get(position).getContent());
			viewHolder.describe_info.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent().setClass(NewHomeActivity.this, AddShareDiscussActivity.class);
					intent.putExtra("shareId", resultList.get(position).getShareId());
					intent.putExtra("position", position);
					startActivityForResult(intent, 1);

				}
			});

			view.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent().setClass(NewHomeActivity.this, AddShareDiscussActivity.class);
					intent.putExtra("shareId", resultList.get(position).getShareId());
					intent.putExtra("position", position);
					startActivityForResult(intent, 1);

				}
			});

			// 分享
			viewHolder.share.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					showOnekeyshare(resultList.get(position).getShareId(), resultList.get(position).getWebUrl(),
							resultList.get(position).getShareContent(), resultList.get(position).getPicUrl(),
							resultList.get(position).getShareTitle());

				}
			});
			// 点击用户头像查看详情
			viewHolder.user_img.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if ("0".equals(resultList.get(position).getIsSectionShare())) {
						if (!resultList.get(position).getShareUserId().equals(DataStore.getInstance().getUserId())) {
							Intent intent = new Intent()
									.setClass(NewHomeActivity.this, FriendPersonalInfActivity.class);
							intent.putExtra("shareUserId", resultList.get(position).getShareUserId());
							startActivity(intent);
						} else {

							Intent intent = new Intent().setClass(NewHomeActivity.this, PersonalInfActivity.class);
							startActivity(intent);

						}

					} else if ("1".equals(resultList.get(position).getIsSectionShare())) {
						Intent intent = new Intent().setClass(NewHomeActivity.this, ClubDetailActivity.class);
						intent.putExtra("sectionId", resultList.get(position).getShareUserId());
						startActivity(intent);
					}

				}
			});

			viewHolder.zan.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					int zan_num = Integer.parseInt(resultList.get(position).getPraiseCount());

					if ("0".equals(resultList.get(position).getPraise())) {
						praiseShare(resultList.get(position).getShareId(), position);
						viewHolder.zan_click.setVisibility(View.VISIBLE);
						viewHolder.zan_click.startAnimation(animation);
						new Handler().postDelayed(new Runnable() {
							public void run() {
								viewHolder.zan_click.setVisibility(View.GONE);
							}
						}, 1000);
						viewHolder.zan.setBackgroundResource(R.drawable.zan_click);

						resultList.get(position).setPraise("1");

						if (zan_num >= 0) {
							zan_num = zan_num + 1;
						}
						viewHolder.zan_count.setText(String.valueOf(zan_num));
						resultList.get(position).setPraiseCount(String.valueOf(zan_num));
					} else {

					}

				}
			});
			if ("0".equals(resultList.get(position).getNewComment())) {
				viewHolder.message_count.setVisibility(View.VISIBLE);
				viewHolder.message_text_new.setVisibility(View.GONE);
				viewHolder.message_count.setText(resultList.get(position).getCommentCount());
			} else {
				viewHolder.message_count.setVisibility(View.GONE);
				viewHolder.message_text_new.setVisibility(View.VISIBLE);
				viewHolder.message_text_new.setText(resultList.get(position).getNewComment());
			}

			if ("0".equals(resultList.get(position).getPraise())) {
				viewHolder.zan.setBackgroundResource(R.drawable.zan);
			} else {
				viewHolder.zan.setBackgroundResource(R.drawable.zan_click);

			}

			viewHolder.zan_count.setText(resultList.get(position).getPraiseCount());

			final ArrayList<Pictures> picList = new ArrayList<Pictures>();
			viewHolder.message.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent().setClass(NewHomeActivity.this, AddShareDiscussActivity.class);
					intent.putExtra("shareId", resultList.get(position).getShareId());
					intent.putExtra("position", position);
					startActivityForResult(intent, 1);

				}
			});

			ImageAdapter adapter = new ImageAdapter(NewHomeActivity.this, picList);
			viewHolder.mGridView.setAdapter(adapter);
			Type type1 = new TypeToken<List<HomeInfoBean>>() {
			}.getType();
			Gson gson1 = new Gson();
			Object fromJson1 = gson1.fromJson(resultList.get(position).getOriginalArr(), type1);
			try {
				resultOriginalList = (List<HomeInfoBean>) fromJson1;
			} catch (Exception e) {
				return null;
			}
			// mGridView = (MyGridView) itemView.findViewById(R.id.mGridView);

			viewHolder.mGridView.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

					if (resultList.get(position) != null && resultList.size() > 0) {
						Type type1 = new TypeToken<List<HomeInfoBean>>() {
						}.getType();
						Gson gson1 = new Gson();
						Object fromJson1 = gson1.fromJson(resultList.get(position).getOriginalArr(), type1);
						try {
							resultOriginalList = (List<HomeInfoBean>) fromJson1;
						} catch (Exception e) {
							return;
						}
						Intent intent = new Intent(NewHomeActivity.this, ClubPhotoActivity.class);
						ArrayList<Pictures> list = new ArrayList<Pictures>();
						if (null != resultOriginalList) {
							list.clear();
							for (int i = 0; i < resultOriginalList.size(); i++) {

								Pictures p = new Pictures();
								p.setUrl(resultOriginalList.get(i).getOriginalUrl());
								list.add(p);
							}
						}

						intent.putExtra("Pictures", list);
						intent.putExtra("currentId", arg2);
						startActivity(intent);
					}
				}
			});

			if ("0".equals(resultList.get(position).getPicCount())) {
				viewHolder.mGridView.setVisibility(View.GONE);
				viewHolder.main_img.setVisibility(View.GONE);
			} else {

				Type type2 = new TypeToken<List<HomeInfoBean>>() {
				}.getType();
				Gson gson2 = new Gson();
				Object fromJson2 = gson2.fromJson(resultList.get(position).getThumbArr(), type2);
				try {
					resultThumbList = (List<HomeInfoBean>) fromJson2;
				} catch (Exception e) {
					return null;
				}
				if (null != resultThumbList && resultThumbList.size() != 0) {
					if ((resultOriginalList.size() == 1)) {
						viewHolder.mGridView.setVisibility(View.GONE);
						viewHolder.main_img.setVisibility(View.VISIBLE);

						imageLoader.displayImage(AppConfig.HOST + resultThumbList.get(0).getThumbUrl(),
								viewHolder.main_img, Constants.image_display_options, AppConfig.animateListener);
						viewHolder.main_img.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View v) {
								Type type1 = new TypeToken<List<HomeInfoBean>>() {
								}.getType();
								Gson gson1 = new Gson();
								Object fromJson1 = gson1.fromJson(resultList.get(position).getOriginalArr(), type1);
								try {
									resultOriginalList = (List<HomeInfoBean>) fromJson1;
								} catch (Exception e) {
									return;
								}
								Intent intent = new Intent(NewHomeActivity.this, ClubPhotoActivity.class);
								ArrayList<Pictures> list = new ArrayList<Pictures>();
								if (null != resultOriginalList) {
									list.clear();

									Pictures p = new Pictures();
									p.setUrl(resultOriginalList.get(0).getOriginalUrl());
									list.add(p);

								}

								intent.putExtra("Pictures", list);
								startActivity(intent);

							}
						});
					} else if (resultOriginalList.size() == 4 || resultOriginalList.size() == 2) {
						viewHolder.main_img.setVisibility(View.GONE);

						picList.clear();
						for (int n = 0; n < resultThumbList.size(); n++) {
							if (n < 6) {
								Pictures p = new Pictures();
								p.setUrl(resultThumbList.get(n).getThumbUrl());
								picList.add(p);
							}
						}
						viewHolder.mGridView.setNumColumns(2);
						viewHolder.mGridView.setVisibility(View.VISIBLE);
						adapter.notifyDataSetChanged();
					} else {
						viewHolder.main_img.setVisibility(View.GONE);
						if (resultThumbList.size() > 6) {
							picList.clear();
							for (int n = 0; n < resultThumbList.size(); n++) {
								if (n < 6) {
									Pictures p = new Pictures();
									p.setUrl(resultThumbList.get(n).getThumbUrl());
									picList.add(p);
								}
							}
						} else if (resultThumbList.size() > 1) {
							picList.clear();
							for (int n = 0; n < resultThumbList.size(); n++) {
								Pictures p = new Pictures();
								p.setUrl(resultThumbList.get(n).getThumbUrl());
								picList.add(p);
							}

						}
						viewHolder.mGridView.setNumColumns(3);
						viewHolder.mGridView.setVisibility(View.VISIBLE);
						adapter.notifyDataSetChanged();
					}

				}

			}

			return view;
		}

		class ViewHolder {

			ImageView user_img;
			HomeGroundImageview main_img;
			TextView user_name;
			TextView time;
			TextView time_middle;

			ImageView watermark;

			EmojiconTextView describe_info;

			TextView message_count, message_text_new, share_text, location;
			Button zan;
			Button zan_click;
			TextView zan_count;
			Button message;
			Button joined;
			ImageButton share;
			ImageButton shield;
			MyGridView mGridView;
		}

	}

	/**
	 * 我也要参加
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void joinToo(final String shareId, final String rbMsgId) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "toRedBagNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("rbMsgId", rbMsgId));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {
				stopProgressDialog();
				String result = (String) object;
				Gson gson = new Gson();
				try {
					mCloudBeansBean = gson.fromJson(result, CloudBeansBean.class);
				} catch (Exception e) {
					return;
				}

				Intent intent = new Intent();
				intent.setClass(NewHomeActivity.this, MainAlertActivity.class);
				intent.putExtra("couponTitle", mCloudBeansBean.getTitle());
				intent.putExtra("logo", mCloudBeansBean.getLogo());
				intent.putExtra("content", mCloudBeansBean.getContent());
				intent.putExtra("shareId", shareId);
				intent.putExtra("rbMsgId", rbMsgId);
				startActivityForResult(intent, 0);

			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	/** 得到手机通讯录联系人信息 **/
	private void getPhoneContacts() {
		ContentResolver resolver = this.getContentResolver();

		// 获取手机联系人
		Cursor phoneCursor = resolver.query(Phone.CONTENT_URI, PHONES_PROJECTION, null, null, null);

		if (phoneCursor != null) {
			while (phoneCursor.moveToNext()) {

				// 得到手机号码
				String phoneNumber = phoneCursor.getString(PHONES_NUMBER_INDEX);
				// 当手机号码为空的或者为空字段 跳过当前循环
				if (TextUtils.isEmpty(phoneNumber))
					continue;

				// 得到联系人名称
				String contactName = phoneCursor.getString(PHONES_DISPLAY_NAME_INDEX);

				// 得到联系人ID
				// Long contactid =
				// phoneCursor.getLong(PHONES_CONTACT_ID_INDEX);

				// 得到联系人头像ID
				// Long photoid = phoneCursor.getLong(PHONES_PHOTO_ID_INDEX);

				mContactsName.add(contactName);
				mContactsNumber.add(phoneNumber);

			}
			Log.e("ContactsNumber", mContactsNumber.toString());
			Log.e("size1", String.valueOf(mContactsNumber.size()));
			Log.e("mContactsName", mContactsName.toString());
			Log.e("size2", String.valueOf(mContactsName.size()));
			phoneCursor.close();

			addDefaultFriend();
		}
	}

	/** 得到手机SIM卡联系人人信息 **/
	private void getSIMContacts() {
		ContentResolver resolver = this.getContentResolver();
		// 获取Sims卡联系人
		Uri uri = Uri.parse("content://icc/adn");
		Cursor phoneCursor = resolver.query(uri, PHONES_PROJECTION, null, null, null);

		if (phoneCursor != null) {
			while (phoneCursor.moveToNext()) {

				// 得到手机号码
				String phoneNumber = phoneCursor.getString(PHONES_NUMBER_INDEX);
				// 当手机号码为空的或者为空字段 跳过当前循环
				if (TextUtils.isEmpty(phoneNumber))
					continue;
				// 得到联系人名称
				String contactName = phoneCursor.getString(PHONES_DISPLAY_NAME_INDEX);

				// Sim卡中没有联系人头像

				mContactsName.add(contactName);
				mContactsNumber.add(phoneNumber);
			}

			phoneCursor.close();
		}
	}

	/**
	 * 获取分享列表
	 */
	@SuppressWarnings("unchecked")
	private void getShareList() {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "queryShareListNew1"));
		// 添加要传递的参数

		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("pageNo", pageNo));
		params.add(new BasicNameValuePair("sectionId", sectionId));
		params.add(new BasicNameValuePair("messageId", groupMessageId));
		params.add(new BasicNameValuePair("pmId", TextUtils.isEmpty(pmId) ? "0" : pmId));
		params.add(new BasicNameValuePair("myFlag", myFlag));
		params.add(new BasicNameValuePair("otherUserId", userId));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {
				mXList.setVisibility(View.VISIBLE);
				stopProgressDialog();
				// mXList.stopRefresh();
				Type type = new TypeToken<List<HomeInfoBean>>() {
				}.getType();
				Gson gson = new Gson();
				String result = (String) object;
				if ("0".equals(result) || "1".equals(result)) {
					Intent next = new Intent(NewHomeActivity.this, PhoneLoginActivity.class);
					// 清空SharedPreferences内数据，重新登录
					SharedPreferences sharedPreferences = getSharedPreferences("login", Context.MODE_PRIVATE);
					Editor editor = sharedPreferences.edit();// 获取编辑器
					editor.clear();
					editor.commit();// 提交修改
					// 清空DataStore
					DataStore.getInstance().setUserId("");
					DataStore.getInstance().setMobile("");
					startActivity(next);
					finish();
				} else {
					Object fromJson = gson.fromJson(result, type);
					try {
						mDataList = (List<HomeInfoBean>) fromJson;
					} catch (Exception e) {
						return;
					}
					if (mDataList != null) {
						if (flgMore) {
							if (mDataList.size() == 0) {
								Toast.makeText(getApplicationContext(), "已经加载全部", Toast.LENGTH_SHORT).show();
								if (!"1".equals(pageNo)) {
									pageNo = String.valueOf(Integer.parseInt(pageNo) - 1);
								} else {
									pageNo = "0";
								}
								resetXList();
							} else {
								for (HomeInfoBean bean : mDataList) {
									resultList.add(bean);
								}
								dataAdapter.addItemLast(mDataList);
								resetXList();

							}
						} else {
							resultList.clear();
							if (mDataList.size() == 0) {

								Toast.makeText(getApplicationContext(), "目前没有分享", Toast.LENGTH_SHORT).show();
								resultList.clear();
								resetXList();
							}
							for (HomeInfoBean bean : mDataList) {
								resultList.add(bean);

							}
							dataAdapter.addItemTop(resultList);
							dataAdapter.notifyDataSetChanged();

							resetXList();
						}

					} else {
						Alert.warn(NewHomeActivity.this, "系统异常");
						resetXList();
					}
				}
			}

			@Override
			public void onFail(String exception) {
				mXList.setVisibility(View.VISIBLE);
				stopProgressDialog();
				Alert.warn(NewHomeActivity.this, "与服务器连接失败，请检查网络");
				resetXList();

			}
		}, DataStore.class, AppConfig.USER).execute(params);
	}

	/**
	 * 获取新消息条数
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void getNewMessageNum() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "queryAlertNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;
				Gson gson = new Gson();
				try {
					mNewMessageNumBean = gson.fromJson(result, NewMessageNumBean.class);
				} catch (Exception e) {
					return;
				}
				if (null != mNewMessageNumBean) {
					if ("0".equals(mNewMessageNumBean.getNewTrend()) && "0".equals(mNewMessageNumBean.getNewInvite())) {

					} else if (!"0".equals(mNewMessageNumBean.getNewTrend())
							&& !"0".equals(mNewMessageNumBean.getNewInvite())) {
						new Handler().postDelayed(new Runnable() {
							public void run() {
								new_message_1.startAnimation(animation_NewMessage_in);
								new_message_1.setVisibility(View.VISIBLE);
								message_content1.setText("新的消息");
								num1.setText(mNewMessageNumBean.getNewTrend());
								imageLoader.displayImage(AppConfig.HOST + mNewMessageNumBean.getTrendIcon(), user_img1,
										Constants.image_display_options_conner);

								new_message_2.startAnimation(animation_NewMessage_in);
								new_message_2.setVisibility(View.VISIBLE);
								message_content2.setText("好友邀约");
								num2.setText(mNewMessageNumBean.getNewInvite());
								imageLoader.displayImage(AppConfig.HOST + mNewMessageNumBean.getInviteIcon(),
										user_img2, Constants.image_display_options_conner);
							}
						}, 1000);
					} else {
						if (!"0".equals(mNewMessageNumBean.getNewTrend())) {
							new_message_2.startAnimation(animation_NewMessage_in);
							new_message_2.setVisibility(View.VISIBLE);
							message_content2.setText("新的消息");
							num2.setText(mNewMessageNumBean.getNewTrend());
							imageLoader.displayImage(AppConfig.HOST + mNewMessageNumBean.getTrendIcon(), user_img2,
									Constants.image_display_options_conner);
						} else {
							new_message_2.startAnimation(animation_NewMessage_in);
							new_message_2.setVisibility(View.VISIBLE);
							message_content2.setText("好友邀约");
							num2.setText(mNewMessageNumBean.getNewInvite());
							imageLoader.displayImage(AppConfig.HOST + mNewMessageNumBean.getInviteIcon(), user_img2,
									Constants.image_display_options_conner);
						}
					}

				} else {
					stopProgressDialog();
					Alert.error(NewHomeActivity.this, "系统异常");
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	public void showOnekeyshare(final String shareId, String shareUrl, String shareContent, String picUrl,
			String ShareTitle) {

		OnekeyShare oks = new OnekeyShare();
		// 分享时Notification的图标和文字
		// oks.setNotification(R.drawable.ic_launcher,
		// this.getResources().getString(R.string.app_name));
		// // address是接收人地址，仅在信息和邮件使用
		// oks.setAddress("12345678901");
		// title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
		oks.setTitle(ShareTitle);
		// // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
		// oks.setTitleUrl("http://sharesdk.cn");
		// text是分享文本，所有平台都需要这个字段
		oks.setText(shareContent);
		// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
		/* oks.setImagePath(MainActivity.TEST_IMAGE); */
		// imageUrl是图片的网络路径，新浪微博、人人网、QQ空间、
		// 微信的两个平台、Linked-In支持此字段

		oks.setImageUrl("".equals(picUrl) ? "http://211.103.20.130:9090/MoveCar2/web/img/fylhIndex.jpg"
				: AppConfig.HOST + picUrl);
		// url仅在微信（包括好s和朋友圈）中使用
		oks.setUrl(shareUrl);
		// appPath是待分享应用程序的本地路劲，仅在微信中使用
		// oks.setAppPath(MainActivity.TEST_IMAGE);
		// // comment是我对这条分享的评论，仅在人人网和QQ空间使用
		// oks.setComment(getContext().getString(R.string.share));
		// // site是分享此内容的网站名称，仅在QQ空间使用
		// oks.setSite(context.getString(R.string.app_name));
		// // siteUrl是分享此内容的网站地址，仅在QQ空间使用
		// oks.setSiteUrl("http://sharesdk.cn");
		// // venueName是分享社区名称，仅在Foursquare使用
		// oks.setVenueName("Southeast in China");
		// // venueDescription是分享社区描述，仅在Foursquare使用
		// oks.setVenueDescription("This is a beautiful place!");
		// // latitude是维度数据，仅在新浪微博、腾讯微博和Foursquare使用
		// oks.setLatitude(23.122619f);
		// // longitude是经度数据，仅在新浪微博、腾讯微博和Foursquare使用
		// oks.setLongitude(113.372338f);
		// // 是否直接分享（true则直接分享）
		// oks.setSilent(silent);
		// // 指定分享平台，和slient一起使用可以直接分享到指定的平台
		// if (platform != null) {
		// oks.setPlatform(platform);
		// }
		// 去除注释可通过OneKeyShareCallback来捕获快捷分享的处理结果
		// oks.setCallback(new OneKeyShareCallback());
		// 通过OneKeyShareCallback来修改不同平台分享的内容
		oks.setCallback(new PlatformActionListener() {

			@Override
			public void onError(Platform arg0, int arg1, Throwable arg2) {
				// Alert.error(NewHomeActivity.this, "分享失败");

			}

			@Override
			public void onComplete(Platform arg0, int arg1, HashMap<String, Object> arg2) {
				transmitShare(shareId);

			}

			@Override
			public void onCancel(Platform arg0, int arg1) {
				Alert.info(NewHomeActivity.this, "分享取消");

			}
		});
		oks.show(this);

	}

	/**
	 * 分享的屏蔽和举报
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void reportShare(String shareId, String reportFlag) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "reportShareNew2")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("shareId", shareId));
		params.add(new BasicNameValuePair("reportFlag", reportFlag));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;

				if ("0".equals(result)) {
				} else {
					stopProgressDialog();
					Alert.error(NewHomeActivity.this, result);
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	/**
	 *
	 * 获取广告图片
	 * 
	 * @author Zhao.JQ
	 */
	@SuppressWarnings("unchecked")
	private void getAdPic() {

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "queryAdvertNew1"));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {
				stopProgressDialog();
				String result = (String) object;
				Gson gson = new Gson();

				try {
					mAdPicBean = gson.fromJson(result, AdPicBean.class);
				} catch (Exception e) {
					return;
				}
				if (null != mAdPicBean) {
					if ("".equals(mAdPicBean.getDefaultLogo())) {
						Type type = new TypeToken<List<AdPicBean>>() {
						}.getType();
						Gson g = new Gson();
						Object fromJson = g.fromJson(mAdPicBean.getAdvertArr(), type);
						try {
							AdPicBeanList = (List<AdPicBean>) fromJson;
						} catch (Exception e) {
							return;
						}
						indicator_imgs = new ImageView[AdPicBeanList.size()];
						initIndicator(AdPicBeanList.size());
						adImg.setAdapter(new HomeAdImagePagerAdapter(NewHomeActivity.this, AdPicBeanList, true)
								.setInfiniteLoop(false));
						adImg.setOnPageChangeListener(new MyOnPageChangeListener());

						adImg.setInterval(5000);
						adImg.startAutoScroll();
						adImg.setCycle(true);
						adImg.setCurrentItem(Integer.MAX_VALUE / 2 - Integer.MAX_VALUE / 2
								% ListUtils.getSize(AdPicBeanList));

					} else {
						AdPicBean bean = new AdPicBean();
						indicator_imgs = new ImageView[AdPicBeanList.size()];
						initIndicator(AdPicBeanList.size());
						bean.setLogo(mAdPicBean.getDefaultLogo());
						AdPicBeanList = new ArrayList<AdPicBean>();
						AdPicBeanList.add(bean);
						adImg.setAdapter(new HomeAdImagePagerAdapter(NewHomeActivity.this, AdPicBeanList, false)
								.setInfiniteLoop(false));
						adImg.setOnPageChangeListener(new MyOnPageChangeListener());

						adImg.setInterval(5000);
						adImg.startAutoScroll();
						adImg.setCycle(true);
						adImg.setCurrentItem(Integer.MAX_VALUE / 2 - Integer.MAX_VALUE / 2
								% ListUtils.getSize(AdPicBeanList));
					}

				} else {
					Alert.warn(NewHomeActivity.this, result);
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.warn(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, DataStore.class, AppConfig.USER).execute(params);

	}

	/**
	 * 初始化引导图标 动态创建多个小圆点，然后组装到线性布局里
	 */
	private void initIndicator(int size) {

		ImageView imgView;
		View v = findViewById(R.id.indicator);// 线性水平布局，负责动态调整导航图标

		for (int i = 0; i < size; i++) {
			imgView = new ImageView(this);
			LinearLayout.LayoutParams params_linear = new LinearLayout.LayoutParams(10, 10);
			params_linear.setMargins(7, 10, 7, 0);
			imgView.setLayoutParams(params_linear);
			indicator_imgs[i] = imgView;

			if (i == 0) { // 初始化第一个为选中状态

				indicator_imgs[i].setBackgroundResource(R.drawable.indicator_focused);
			} else {
				indicator_imgs[i].setBackgroundResource(R.drawable.indicator);
			}
			((ViewGroup) v).addView(indicator_imgs[i]);
		}

	}

	/**
	 * 是否获取通讯录
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void isCheckContact() {

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "checkContactNew3"));
		// 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("mobileType", "0"));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;

				if (null != result) {

					if ("0".equals(result)) {
						// 获取通讯录信息

						getPhoneContacts();

					} else if ("1".equals(result)) {
						stopProgressDialog();

					} else {
						Alert.warn(NewHomeActivity.this, result);
					}
				} else {
					Alert.warn(NewHomeActivity.this, "系统异常!");
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.warn(NewHomeActivity.this, "与服务器连接失败，请检查网络");

			}
		}, DataStore.class, AppConfig.USER).execute(params);

	}

	@Override
	public void onRefresh() {
		flgMore = false;
		resultList.clear();
		pageNo = "0";
		if (!TextUtils.isEmpty(userId)) {
			startProgressDialog();
			getShareList();
		} else {
			startProgressDialog();

			getShareList();
		}

	}

	@Override
	public void onLoadMore() {
		flgMore = true;
		pageNo = String.valueOf(Integer.parseInt(pageNo) + 1);
		if (!TextUtils.isEmpty(userId)) {
			// startProgressDialog();
			getShareList();
		} else {
			// startProgressDialog();
			getShareList();
		}
	}

	private void startProgressDialog() {
		if (progressDialog == null) {
			progressDialog = CustomProgressDialog.createDialog(this);
			progressDialog.setMessage("正在加载...");
		}

		progressDialog.show();
	}

	private void startProgressDialog(String message) {
		if (progressDialog == null) {
			progressDialog = CustomProgressDialog.createDialog(this);
			progressDialog.setMessage(message);
		}

		progressDialog.show();
	}

	private void stopProgressDialog() {
		if (progressDialog != null) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}

	public class MyOnPageChangeListener implements OnPageChangeListener {

		@Override
		public void onPageSelected(int position) {
			// 改变所有导航的背景图片为：未选中
			for (int i = 0; i < indicator_imgs.length; i++) {

				indicator_imgs[i].setBackgroundResource(R.drawable.indicator);

			}

			// 改变当前背景图片为：选中
			indicator_imgs[position].setBackgroundResource(R.drawable.indicator_focused);

		}

		@Override
		public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}
}
